package shuailong;

import socket.Print;

/**
 * Created by zzy on 2018/1/17.
 */
public class B3 {
    public static void main(String[] args) {
        String s="我ABC汉DEF";
        Print.print(B3.substring(s,6));
    }

    public static String substring(String s,int length){
        char[] cs=s.toCharArray();
        StringBuilder builder=new StringBuilder();
        int count=0;
        for (char c:cs){
            if(isAsc(c)){
                count++;
            }else {
                count+=2;
            }
            if(count>length){
                break;
            }
            builder.append(c);
        }
        return builder.toString();
    }

    private static boolean isAsc(char c) {
        return c<128;
    }
}
